package com.infore.airsupervise.biz.impl;

import com.infore.airsupervise.R;
import com.infore.airsupervise.app.Constants;
import com.infore.airsupervise.app.MsgConst;
import com.infore.airsupervise.app.StatusConst;
import com.infore.airsupervise.bean.AirStationE;
import com.infore.airsupervise.bean.MapPoint;
import com.infore.airsupervise.bean.PersonRouteE;
import com.infore.airsupervise.biz.StationMapShowBiz;
import com.infore.airsupervise.http.BaseResponse;
import com.infore.airsupervise.http.HttpAPI;
import com.infore.airsupervise.http.HttpCallBack;
import com.infore.airsupervise.http.HttpUtil;
import com.infore.airsupervise.http.OnServerResponseListener;
import com.infore.airsupervise.utils.JSONUtil;

import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import retrofit2.Call;

/**
 * @features:
 * @author: WuTao
 * @date: 2017/3/21 14:30
 */
public class StationMapShowBizImpl implements StationMapShowBiz{
    @Override
    public Call<BaseResponse> sendStationRealDetailRequest(final OnServerResponseListener<List<AirStationE>> listener) {

        Call<BaseResponse> call = HttpUtil.getHttpService().postParams(HttpAPI.GET_STATION_MAP, Collections.EMPTY_MAP);
        call.enqueue(new HttpCallBack() {
            @Override
            public void onSuccess(int operationCode, BaseResponse response) {
                super.onSuccess(operationCode, response);
                List<AirStationE> stationEList= JSONUtil.parseList(
                        response.getData(), Constants.RESPONSE_BEAN_LIST_KEY, AirStationE.class);
                // 地图中心点
//                MapPoint centerPoint = JSONUtil.parseBean(response.getData(), "mapCenter", MapPoint.class);
                listener.onSucceed(stationEList, response.getMessage());
            }

            @Override
            public void onFailed(int operationCode, String desc) {
                super.onFailed(operationCode, desc);
                listener.onFailed(StatusConst.CODE_OPERATION_FAIL, MsgConst.GET_DATA_FAILED,desc);
            }

            @Override
            public void onException(int errorCode, String title, String desc) {
                super.onException(errorCode, title, desc);
                listener.onFailed(errorCode,title,desc);
            }


        });
        return call;
    }

    @Override
    public Call<BaseResponse> sendPersonRouteRequest(String userId ,
                                                     String time, final OnServerResponseListener<List<PersonRouteE>> listener) {
        Map<String ,Object> params = new HashMap<>();
        params.put(Constants.USER_ID_KEY , userId);
        params.put("time" , time);
        Call<BaseResponse> call = HttpUtil.getHttpService().postParams(HttpAPI.GET_PSON_ROUTE,params);
        call.enqueue(new HttpCallBack(){
            @Override
            public void onSuccess(int operationCode, BaseResponse response) {
                super.onSuccess(operationCode, response);
                List<PersonRouteE> routeListe= JSONUtil.parseList(
                        response.getData(), Constants.RESPONSE_BEAN_LIST_KEY, PersonRouteE.class);
                listener.onSucceed(routeListe, response.getMessage());
            }

            @Override
            public void onFailed(int operationCode, String desc) {
                super.onFailed(operationCode, desc);
                listener.onFailed(StatusConst.CODE_OPERATION_FAIL, MsgConst.GET_DATA_FAILED,desc);
            }

            @Override
            public void onException(int errorCode, String title, String desc) {
                super.onException(errorCode, title, desc);
                listener.onFailed(errorCode,title,desc);
            }

        });
        return null;
    }
}
